package com.homegoods.designer.ui.fragments;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.homegoods.designer.DesignerApiUtils;
import com.homegoods.designer.R;
import com.kedll.library.mvp.BasePresenter;
import com.kedll.library.util.StringUtil;
import com.kedll.library.util.ToastUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author QiQi
 * @ClassName: ApplyFreedomDesignerFragment
 * @date 2018/10/6
 * @description 申请认证独立自由设计师
 */
public class ApplyFreedomDesignerFragment extends BaseApplyDesignerFragment {
    private EditText applyfreedom_name, ed_year;
    private RadioGroup rg_work;
    private RadioButton rb_work_yes;

    @Override
    protected void init() {
        super.init();
        applyfreedom_name = (EditText) findViewById(R.id.applyfreedom_name);
        ed_year = (EditText) findViewById(R.id.ed_year);
        rg_work = (RadioGroup) findViewById(R.id.rg_work);
        rb_work_yes = (RadioButton) findViewById(R.id.rb_work_yes);
    }

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        super.initEvent(savedInstanceState);

    }

    /**
     * cmd=Adddesigner      //方法名
     * outdata=jsonlist     //数据防护方式
     * category=0           //0代码设计机构，1代表独立设计师
     * corp=格力        //公司信息：只有当申请设计机构才传
     * city=上海            //所在城市
     * name=张三            //真实姓名
     * sex=0                //0代表男，1代表女
     * phone=13122937698    //手机号
     * mailbox=@qq.cpm      //邮箱
     * rates=0              //收费标准
     * cost=90              //平均造价
     * yearsizao=0          //年均私宅数
     * decoration=0         //总共家装数量
     * construction=0       //0做过施工，1没有
     * comers=1990-09  //入行年份注：只有当申请独立设计师才传
     * TODO
     */
    private void submit() {
        Map<String, Object> params = new HashMap<>();
        params.put("cmd", "Adddesigner");
        params.put("outdata", "jsonlist");
        params.put("category", "1");
        params.put("corp", "");
        params.put("city", getArea());
        params.put("name", applyfreedom_name.getText().toString().trim());
        params.put("sex", getSex());
        params.put("phone", getPhone());
        params.put("mailbox", getMail());
        params.put("rates", getChargeStandard());
        params.put("cost", getCost());
        params.put("yearsizao", getPastProjects());
        params.put("decoration", getAllProjects());
        params.put("construction", getOperation());
        params.put("comers", ed_year.getText().toString().trim());
        DesignerApiUtils.addDesigner(params, jsonObject -> {

        }, throwable -> {

        });

    }

    /**
     * 验证填写信息是否为空
     *
     * @return
     */
    private boolean validateEdit() {
        if (StringUtil.isEmpty(ed_year.getText().toString().trim())) {
            ToastUtil.showToast("请输入入行年份");
            return false;
        }
        if (StringUtil.isEmpty(applyfreedom_name.getText().toString().trim())) {
            ToastUtil.showToast("请输入姓名");
            return false;
        }
        if (!validateBaseEdit()) {
            return false;
        }
        return true;
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.designer_include_design_person;
    }

//    private RadioGroup.OnCheckedChangeListener workListen = (group, checkedId) -> {
//        int id = group.getCheckedRadioButtonId();
//        if (id == R.id.rb_man) {
//            mSex = "男士".equals(rb_man.getText().toString()) ? 0 : 1;
//        } else {
//            mSex = 1;
//        }
//    };
}
